import axios from 'axios'
import {ElMessageBox, ElMessage} from 'element-plus'


// 创建axios实例
const request = axios.create({
    // axios中请求配置有baseURL选项，表示请求URL公共部分
    baseURL: '',
    // 超时
    timeout: 10000
})

// request拦截器
request.interceptors.request.use(config => {
    //添加请求头
    config.headers['Content-Type'] = 'application/json;charset=utf-8'
    return config
}, error => {
    ElMessage({message: error, type: 'error'})
    return Promise.reject(error)
})

// 响应拦截器
request.interceptors.response.use(
    (res) => {
        return Promise.resolve(res)
    },
    error => {
        ElMessage({message: error, type: 'error'})
        return Promise.reject(error)
    }
)
export default request
